package com.alibaba.citrus.cr.common.enums.ordercenter;

import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Getter
public enum OrderCategoryEnum {

    COMPANY("100", "分子公司"),
    GROUP("200", "集团"),
    STOCK("300", "一盘货"),
    ;

    @SerializedName(value = "code")
    private final String code;
    @SerializedName(value = "desc")
    private final String desc;

    OrderCategoryEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static OrderCategoryEnum of(String code) {
        return Arrays.stream(OrderCategoryEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        OrderCategoryEnum orderCategoryEnum = of(code);
        return Objects.nonNull(orderCategoryEnum) ? orderCategoryEnum.getDesc() : "";
    }

    public static List<String> codes() {
        return Lists.newArrayList(OrderCategoryEnum.COMPANY.getCode(), OrderCategoryEnum.STOCK.getCode());
    }
}
